package com.example.ssm.controller;

import com.example.ssm.mapper.EmployeeMapper;
import com.example.ssm.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * spring mvc 映射请求参数时依赖编译器保留的参数局部变量名
 *  保留或者显示声明
 */
@Controller
public class EmployeeController {

    @RequestMapping("/success")
    public String index() {
        return "success";
    }

    @Autowired
    private EmployeeMapper employeeMapper;

    @GetMapping("/employee")
    public String getEmpById(@RequestParam("id") Long id,
                             Model model) {
        Employee e =  employeeMapper.getById(id);
        model.addAttribute("e", e);
        return "success";
    }

}
